<html>
<head><meta charset="utf-8"><title>Is there a way to get the span of the crate root? · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Is.20there.20a.20way.20to.20get.20the.20span.20of.20the.20crate.20root.3F.html">Is there a way to get the span of the crate root?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="235737992"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Is%20there%20a%20way%20to%20get%20the%20span%20of%20the%20crate%20root%3F/near/235737992" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Is.20there.20a.20way.20to.20get.20the.20span.20of.20the.20crate.20root.3F.html#235737992">(Apr 22 2021 at 19:52)</a>:</h4>
<p>I want to add a suggestion to add a crate-level attribute.</p>



<a name="235738935"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Is%20there%20a%20way%20to%20get%20the%20span%20of%20the%20crate%20root%3F/near/235738935" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cjgillot <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Is.20there.20a.20way.20to.20get.20the.20span.20of.20the.20crate.20root.3F.html#235738935">(Apr 22 2021 at 19:59)</a>:</h4>
<p><code>tcx.hir().krate().item.inner</code> should work.</p>



<a name="235739272"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Is%20there%20a%20way%20to%20get%20the%20span%20of%20the%20crate%20root%3F/near/235739272" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Is.20there.20a.20way.20to.20get.20the.20span.20of.20the.20crate.20root.3F.html#235739272">(Apr 22 2021 at 20:01)</a>:</h4>
<p>hmm ok, no way to do it with only a <code>Session</code> then I guess</p>



<a name="235739278"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Is%20there%20a%20way%20to%20get%20the%20span%20of%20the%20crate%20root%3F/near/235739278" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Is.20there.20a.20way.20to.20get.20the.20span.20of.20the.20crate.20root.3F.html#235739278">(Apr 22 2021 at 20:01)</a>:</h4>
<p>thank you though!</p>



<a name="235739470"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Is%20there%20a%20way%20to%20get%20the%20span%20of%20the%20crate%20root%3F/near/235739470" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cjgillot <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Is.20there.20a.20way.20to.20get.20the.20span.20of.20the.20crate.20root.3F.html#235739470">(Apr 22 2021 at 20:02)</a>:</h4>
<p>No, you need either the AST or the HIR.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>